AddCSLuaFile( "shared.lua" )

include('shared.lua')

function ENT:Initialize()
	self.Entity:SetModel("models/rocket/rocket.mdl")
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	local phys = self.Entity:GetPhysicsObject()
	local trail = util.SpriteTrail(self.Entity, 0, Color(255,255,255), false, 25, 1, 0.25, 1/(15+1)*0.5, "trails/smoke.vmt")
	
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableGravity( false )
		phys:EnableDrag( false )
		phys:SetMass(20)
	end
end

function ENT:PhysicsCollide( data, physobj )
	if(data.HitEntity:IsWorld())then
		local explosion = ents.Create( "env_explosion" ) // Creating our explosion
		explosion:SetKeyValue( "spawnflags", 144 ) //Setting the key values of the explosion 
		explosion:SetKeyValue( "iMagnitude", 15 ) // Setting the damage done by the explosion
		explosion:SetKeyValue( "iRadiusOverride", 128 ) // Setting the radius of the explosion 
		explosion:SetPos(self:GetPos()) // Placing the explosion where we are
		explosion:Spawn( ) // Spawning it
		explosion:Fire("explode","",0)
		self.Entity:Remove()
	end
end

function ENT:Touch( ent)
		local box = false
		for k,v in pairs(ents.FindByClass("sent_bomb")) do
			if(ent == v)then
				box = true
			end
		end
		for k,v in pairs(ents.FindByClass("sent_missle")) do
			if(ent == v)then
				box = true
			end
		end
		for k,v in pairs(ents.FindByClass("func_door_rotating")) do
			if(ent == v)then
				box = true
			end
		end
		for k,v in pairs(ents.FindByClass("func_door")) do
			if(ent == v)then
				box = true
			end
		end
		for k,v in pairs(ents.FindByClass("func_tracktrain")) do
			if(ent == v)then
				box = true
			end
		end
		if ((ent:IsVehicle()) or (box == true))then
			local explosion = ents.Create( "env_explosion" ) // Creating our explosion
			explosion:SetKeyValue( "spawnflags", 144 ) //Setting the key values of the explosion 
			explosion:SetKeyValue( "iMagnitude", 15 ) // Setting the damage done by the explosion
			explosion:SetKeyValue( "iRadiusOverride", 128 ) // Setting the radius of the explosion 
			explosion:SetPos(self:GetPos()) // Placing the explosion where we are
			explosion:Spawn( ) // Spawning it
			explosion:Fire("explode","",0)
			self.Entity:Remove()
		end
end